package tech.edwardvan.quartzdemo.job;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 调度任务
 *
 * @author EdwardVan
 */
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
@Setter
@Slf4j
public class DemoJob implements Job {

    @Autowired
    private Scheduler scheduler;

    /**
     * 通过setter方法获得datamMap的值,跟传入参数的key相同
     */
    private String taskName;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobKey jobKey = jobExecutionContext.getJobDetail().getKey();
        log.info("Job id is:{},name is {}", jobKey.getName(), taskName);
        TriggerKey triggerKey = jobExecutionContext.getTrigger().getKey();
        log.info("Trigger name is:{}", triggerKey.getName());

        //推荐使用getMergedJobDataMap方法，Trigger的key优先级别高于jobDetail
        JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
    }
}
